<?php
require_once('PHPUnit/Extensions/Database/TestCase.php');
require_once('./includes/phpunit_setup.inc');
class swen_module_Test extends DrupalTddTestCase {
  var $primary_vocabulary = 1;
  public function setup() {
    parent::setup();
    drupal_install_modules(array('swen', 'devel'));
    db_query("INSERT INTO {dict}(EnglishWord, EnglishSortBy, 
                                 SwahiliWord, SwahiliSortBy) 
              VALUES('dog', 'dog', 'mbwa', 'mbwa')");
  }

  function testPaldoBackfillVars() {
    $en_sw_vars = _swen_paldoclient_vars('dog', 'en', 'sw');
    $this->assertEquals('dog', $en_sw_vars['kclient_query'], 'Query not set'); 
    $this->assertEquals('en', $en_sw_vars['kclient_db'], 'DB not set'); 
    $this->assertEquals('sw', $en_sw_vars['kclient_link'], 'Link not set'); 
    $this->assertEquals('http://sitesearch.kamusi.org', $en_sw_vars['kclient_dom'],
                        'Domain not set'); 
    $this->assertEquals('html', $en_sw_vars['kclient_format'], 'Javascript format'); 
    $this->assertEquals('kamusi', $en_sw_vars['kclient_key'], 'Key not set'); 

    $js = _do_lookup('notfound', 1);
    $this->assertEquals('</script>', substr($js, -9 ));
  }

  function testResults() {
    $rows = _swen_get_results('dog', 'en');
    $this->assertEquals(1, count($rows), 'Expecting 1 result');
    $rows = _swen_get_results('d*', 'en');
    $this->assertEquals(1, count($rows), 'Expecting 1 result for wildcard query d*');
    $rows = _swen_get_results('mbwa', 'sw');
    $this->assertEquals(1, count($rows), 'Expecting 1 result');
    $rows = _swen_get_results('m*', 'sw');
    $this->assertEquals(1, count($rows), 'Expecting 1 result for wildcard query m*');
  }
}

